import { MockMethod } from 'vite-plugin-mock'

// 用户登录接口
const login = {
  url: '/api/user/login',
  method: 'post',
  response: ({ body }) => {
    const { username, password } = body
    
    if (username === 'admin' && password === 'admin') {
      return {
        code: 200,
        data: {
          token: 'mock-token-admin',
          username: 'admin',
          avatar: 'A',
          roles: ['admin']
        },
        message: '登录成功'
      }
    } else {
      return {
        code: 401,
        data: null,
        message: '用户名或密码错误'
      }
    }
  }
}

// 获取用户信息接口
const getUserInfo = {
  url: '/api/user/info',
  method: 'get',
  response: (request) => {
    const token = request.headers?.authorization?.replace('Bearer ', '')
    
    if (token === 'mock-token-admin') {
      return {
        code: 200,
        data: {
          userId: '1',
          username: 'admin',
          realName: '管理员',
          avatar: 'A',
          roles: ['admin'],
          permissions: ['*:*:*'] // 所有权限
        },
        message: '获取用户信息成功'
      }
    } else {
      return {
        code: 401,
        data: null,
        message: 'token无效或已过期'
      }
    }
  }
}

// 退出登录接口
const logout = {
  url: '/api/user/logout',
  method: 'post',
  response: () => {
    return {
      code: 200,
      data: null,
      message: '退出成功'
    }
  }
}

export default [
  login,
  getUserInfo,
  logout
] as MockMethod[] 